import { Component, Vue } from 'vue-property-decorator'
import { Menu } from '@entity/common';
import { UserHiddenRoots, User } from '@entity/user';
import OtherUserInfo from './other/Index.vue'
import UserBox from '@profile/util/user_box/Index.vue';
import Guide from '@guide';
import axios from '@axios/user'

@Component({
    components: {
        UserBox, Guide, OtherUserInfo
    }
})
export class ProfileView extends Vue {

    /** 目录 */
    private guideList: Array<Menu> = [
        new Menu('个人资料', '/profile/base'),
        new Menu('账号设置', '/profile/account'),
        new Menu('加我好友', '/profile/addme'),
        new Menu('个性设置', '/profile/custom'),
        new Menu('学生认证', '/profile/student')
    ];

    /** 用户 */
    private user: User = new User();

    /** 权限 */
    private roots: UserHiddenRoots = new UserHiddenRoots();

    /** 模式（自己/他人） */
    private mode: String = 'custom';

    /**
     * 如果路由中没有指定用户 id, 说明是自己模式,
     * 自己模式下只需要从 vuex 取出信息即可
     * 否则需要根据路由中的 id, 去服务器拿数据,
     * 获取到用户信息, 隐藏权限
     */
    created() {
        if (this.$route.params.id != undefined) {
            let target: Number = Number.parseInt(this.$route.params.id)
            axios.base.queryById(target).then(res => {
                this.user = res.user;
                this.roots = res.roots;
                this.$store.commit('addUser', this.user);
            })
        } else {
            this.mode = 'self';
            this.user = this.$store.getters.me();
        }
    }
}